twitter和facebook等如何制作独特的网址,例如.twitter.com/billgates
如果我想做同样的事情(给我的用户使用用户名的唯一网址),它是一个应用程序还是你为每个用户创建一个索引页面的目录?
顺便说一句,我使用coldfusion.
谢谢
我的网站中有链接将查询传递给从外部数据库查询的页面.这很好,例如
mysite.com/catalog/?tl=flooring
Run Code Online (Sandbox Code Playgroud)
但是我想重写这个url以显示为
mysite.com/catalog/flooring
Run Code Online (Sandbox Code Playgroud)
我曾尝试修改wordpress中的重写规则,但它总是显示索引页面
add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
add_filter('query_vars','wp_insertMyRewriteQueryVars');
add_filter('init','flushRules');
// Remember to flush_rules() when adding rules
function flushRules(){
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
// Adding a new rule
function wp_insertMyRewriteRules($rules)
{
$newrules = array();
$newrules['(catalog)/([a-zA-Z0-9 ]+)$'] = '/catalog/?tl=$matches[2]';
return $newrules + $rules;
}
// Adding the id var so that WP recognizes it
function wp_insertMyRewriteQueryVars($vars)
{
array_push($vars, 'id');
return $vars;
}
Run Code Online (Sandbox Code Playgroud) 我有一种情况,我需要在 nginx 中的所有请求中附加一个国家/地区代码。
例如,如果用户访问http://example.com:3333/html/about,那么我应该重定向(在 nginx 中使用重写)到http://example.com:3333/html/about?country_code=en
我有以下重写,但我得到“太多循环”。
rewrite ^(.*)$ http://$host:3333/$1?country_code=en last;
Run Code Online (Sandbox Code Playgroud)
我如何解决它?
配置文件
server {
### USA specific config ###
if ($geoip_country_code = US) {
# do something here for USA visitors;
# root path /var/www/html/content/usa/;
rewrite ^(.*)$ http://$host:3333/$1?country_code=en last;
}
}
Run Code Online (Sandbox Code Playgroud) 请帮忙改写网址
http://www.site.com/index.php?cat=catname
和
http://www.site.com/index.php?id=productname
像这样
http://www.site.com/catname
和
http://www.site.com/productname
我认为它需要 php 检查页面是 cat 将它作为 cat 使用还是它的产品将它作为产品使用
例如,我有带有 url 的页面,页面上 http://mysite.com?page=3&var=10也有表单。
当表单提交时,php 中有一些操作,但我需要?page=3&var=10在表单以某种方式提交后删除它,有没有办法在没有 mod_rewrite 的情况下通过 PHP 兼容所有浏览器?
我的rewriterule和目录索引有问题
DirectoryIndex invite.php about.php account.php
RewriteRule ^/?([a-z0-9_-]+)/?$ /user.php?u=$1 [L]
Run Code Online (Sandbox Code Playgroud)
可以说about.php是在about文件夹中.当我访问www.url.com/about/about.php时,它运行正常.但是当我去的时候www.url.com/about/,它会进入我的user.php页面.当我去www.url.com/about,(没有结束斜线),它去www.url/about/?u=about
谁能帮我?
与此同时,我正在尝试设置用户可以去的地方www.url.com/andrewliu而不是www.url.com/user.php?u=andrewliu
我想我需要以某种方式修复我的结尾斜线和重定向?
谢谢!
编辑
我有这个
DirectoryIndex invite.php about.php account.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^/?([a-z0-9_-]+)/?$ /user.php?u=$1 [L]
RewriteCond %{QUERY_STRING} !^b= [NC]
RewriteRule ^(business)/(.*)$ /$1/index.php?b=$2 [L,NC,QSA]
Run Code Online (Sandbox Code Playgroud) 我不熟悉.htaccess文件,请原谅我,如果我的问题有点荒谬.
当我要求时
localhost/mydomain/blog.php
Run Code Online (Sandbox Code Playgroud)
我想要一个这种形式的网址:
localhost/mydomain/blog/
Run Code Online (Sandbox Code Playgroud)
我的网站目录如下:

.htaccess文件包括以下内容:
删除.php扩展名
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
有了这个链接
<a href="blog">Blog</a>
Run Code Online (Sandbox Code Playgroud)
网址是:
localhost/createforweb_1.1/blog
Run Code Online (Sandbox Code Playgroud)
但我想添加一个尾部斜杠,所以如果我在htaccess中添加这些行:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://localhost/createforweb_1.1/$1/ [L,R=301]
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
The requested URL /blog/.php was not found on this server.
Run Code Online (Sandbox Code Playgroud)
我确定很简单,但我在.htaccess重写方面有一点经验!
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
# RewriteBase /
</IfModule>
Options -MultiViews
## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . …Run Code Online (Sandbox Code Playgroud) 我的网站使用URL Rewrite来制作SEO友好的URL.这使得自我发布表单回到同一页面有点棘手.
但是在ColdFusion中,我为表单的action属性执行此操作:
<form name="formSortBy" method="post" enctype="multipart/form-data" action="#StructFind(GetHttpRequestData().headers, 'X-Original-URL')#">
</form>
Run Code Online (Sandbox Code Playgroud)
这里的重要部分是#StructFind(GetHttpRequestData().headers, 'X-Original-URL')#获取页面的URL.
但是这个X-Original-URL键在某些页面上不存在,所以我从ColdFusion中得到一个错误:
Cannot find X-Original-URL key in structure.
The specified key, X-Original-URL, does not exist in the structure.
Run Code Online (Sandbox Code Playgroud)
当我点击进入我所在部分的主页时就会发生这种情况.X-Original-URL如果我去,http://www.sitename.com/products/gaming那就存在但是如果我去的话它将不存在http://www.sitename.com/products
反正有没有解决这个问题或让它像我需要的那样工作?
我正在尝试将地址名称从url路径重写为nginx上的查询字符串.
我想ourdomain.com/hotels/london?some_key=value成为ourdomain.com?d=london&some_key=value
我们用Apache做的 -
RewriteRule ^hotels/([^/]+)/?\??(.*)$ ?d=$1&$2 [QSA]
Run Code Online (Sandbox Code Playgroud)
我们目前正在使用haProxy(充当反向代理) -
reqrep ^([^\ :]*)\ /hotels/([^/\ \?]+)/?\??([^\ ]*)(.*)$ \1\ /?d=\2&\3\4
Run Code Online (Sandbox Code Playgroud)
我如何在nginx上做同样的事情?
我正在尝试使用BrowserRouter使我的路由与IIS和React Router v4一起使用。
在我的本地主机上,我的所有路由均按预期工作。React Router可以像我希望的那样处理所有事情:
现在,在IIS中,我设置了一个忽略'/ appfolder / api / *'的规则,目的是为我的应用程序提供api。这样可行。
如何使IIS重定向到“ http://www.example.com/appfolder/dest/CODE ”,并使React Router根据其规则进行处理。如果我重定向到'/appfolder/index.html',我会放开我想保留给ReactRouter处理的'CODE'。
如果我尝试使用正则表达式捕获组重定向到“ http://www.example.com/appfolder/dest/CODE ”,则会收到“ ERR_TOO_MANY_REDIRECTS”。
我的web.config中目前有以下规则:
<rule name="ReactRouter Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/appfolder/api/" negate="true" />
</conditions>
<action type="Redirect" url="/appfolder/dest/CODE" />
<!-- also tried this -->
<!-- action type="Redirect" url="/appfolder/index.html" /-->
</rule>
Run Code Online (Sandbox Code Playgroud) url-rewriting ×10
.htaccess ×3
mod-rewrite ×3
php ×3
coldfusion ×2
nginx ×2
apache ×1
facebook ×1
iis ×1
iis-7.5 ×1
react-router ×1
reactjs ×1
twitter ×1
url ×1
url-routing ×1
wordpress ×1